package com.wmx.config;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;
import java.util.UUID;

/**
 * JPA 实体主键为字符串类型时，自定义主键生成器。
 *
 * @author wangMaoXiong
 * @version 1.0
 * @date 2023/5/20 22:03
 */
public class StringIdGenerator implements IdentifierGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}